package org.recruit.system.controller;


import org.recruit.system.domain.CompanyRecruit;
import org.recruit.system.service.ICompanyRecruitService;
import org.recruit.system.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 招聘信息Controller
 *
 * @author teapot
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/system/recruit")
public class CompanyRecruitController {
    private String prefix = "system/recruit";

    @Autowired
    private ICompanyRecruitService companyRecruitService;

    @GetMapping()
    public String recruit() {
        return prefix + "/recruit";
    }

    /**
     * 查询招聘信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(CompanyRecruit companyRecruit) {
        //  startPage();
        List<CompanyRecruit> list = companyRecruitService.selectCompanyRecruitList(companyRecruit);
        return AjaxResult.success(list);
    }

    /**
     * 新增招聘信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存招聘信息
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyRecruit companyRecruit) {
        return AjaxResult.success(companyRecruitService.insertCompanyRecruit(companyRecruit));
    }

    /**
     * 修改招聘信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CompanyRecruit companyRecruit = companyRecruitService.selectCompanyRecruitById(id);
        mmap.put("companyRecruit", companyRecruit);
        return prefix + "/edit";
    }

    /**
     * 修改保存招聘信息
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyRecruit companyRecruit) {
        return AjaxResult.success(companyRecruitService.updateCompanyRecruit(companyRecruit));
    }

    /**
     * 删除招聘信息
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return AjaxResult.success(companyRecruitService.deleteCompanyRecruitByIds(ids));
    }
}
